package com.lu.controller;

import com.lu.bean.AppException;
import com.lu.bean.ResBean;
import com.lu.constant.ErrorEnum;
import com.lu.service.RiddleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author luke
 * @className RiddleController
 * @description
 * @date 2021/07/13 10:21
 */
@Slf4j
@RestController
@Api(tags = "选词接口")
public class RiddleController {

    @Resource
    private RiddleService riddleService;

    /**
     * @description 提供选词列表
     * @author luke
     * @date 2021/7/13 10:32
     * @return com.lu.bean.ResBean
     */
    @ApiOperation("获取选词列表")
    @RequestMapping(value = "/riddle/queryRiddle", method = RequestMethod.GET)
    public ResBean queryRiddle(){
        ResBean res = new ResBean();
        try {
            String[] riddles = riddleService.queryRiddle();
            res.setData(riddles);
        } catch (AppException e) {
            log.error("AppException occur,{},",e.toString(),e);
            res.setByAppException(e);
        } catch (Exception e) {
            log.error("Exception occur,",e);
            res.setResCode(ErrorEnum.FAIL.code);
            res.setResMsg("服务器异常");
        }
        return res;
    }

}
